import { Injectable } from '@angular/core';
import { CookieService } from 'ngx-cookie-service';
import { Subject } from 'rxjs';
import { AppConfig } from '../../domain/appconfig';

@Injectable()
export class AppConfigService {
  config: AppConfig = {
    theme: 'md-light-indigo',
    dark: false,
    inputStyle: 'outlined',
    ripple: true,
  };

  private configUpdate = new Subject<AppConfig>();

  configUpdate$ = this.configUpdate.asObservable();

  constructor(private cookieService: CookieService) {
    const theme = cookieService.get('theme');
    console.log(theme)
    if (theme != '') {
      this.config.theme = theme;
    }
    console.log(this.config)
  }

  updateConfig(config: AppConfig) {
    this.config = config;
    this.configUpdate.next(config);
  }

  getConfig() {
    return this.config;
  }
}
